package com.chen.common.security.utils;

import lombok.experimental.UtilityClass;
import org.springframework.security.core.parameters.P;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: ~龙~
 * @date: 2023/6/13 11:25
 **/
@UtilityClass
public class HttpServletUtils {

    /**
     * 从请求中解析出参数map
     * 注：不适合用于集合类型的参数
     * @param request 请求
     * @return 参数map，K：参数名  V：参数值
     */
    public Map<String, String> paramMap(HttpServletRequest request){
        Map<String, String[]> parameterMap = request.getParameterMap();
        if (parameterMap == null || parameterMap.isEmpty()){
            return new HashMap<>();
        }

        Map<String, String> map = new HashMap<>();
        for (String key : parameterMap.keySet()) {
            map.put(key,parameterMap.get(key)[0]);
        }

        return map;
    }
}
